/*
 * @Description: 请求数据
 * @Author: guangzan
 * @Date: 2019-04-04 09:01:43
 * @LastEditTime: 2019-04-04 11:01:47
 */
const request = {}

const host = "https://api.github.com/";

/**
 * @description: post请求
 * @param {url, postData, doSuccess}
 * @param url：接口
 * @param postData：参数，json类型
 * @param doSuccess：成功的回调函数
 */
request.pRequest = function (url, postData, doSuccess) {
    wx.request({
        url: host + url,
        header: {
            "content-type": "application/json;charset=UTF-8"
        },
        data: postData || {},
        method: 'POST',
        success: function (res) {
            doSuccess(res.data);
        },
        fail: function () {
            console.log('请求失败');
        },
    })
};
/**
 * @description: get请求
 * @param {url, doSuccess, doFail}
 * @param url：接口
 * @param doSuccess：成功的回调函数
 */
request.gRequest = function (url, doSuccess) {
    wx.request({
        url: host + url,
        header: {
            "content-type": "application/json;charset=UTF-8"
        },
        method: 'GET',
        success: function (res) {
            doSuccess(res.data);
        },
        fail: function () {
            console.log("请求失败");
        },
    })
};

module.exports = request;